<template>
  <div id="shoppinglist">
    <div id="top">
      <span class="iconfont arrow_l" @click="goback">&#xe6bc;</span>
      <h2>小U商城</h2>
      <p>
        <span class="iconfont">&#xf0112;</span>
        <span class="iconfont">&#xe71e;</span>
        <i class="line"></i>
      </p>
    </div>
    <!-- 搜索框 -->
    <div id="inp">
      <input
        type="text"
        placeholder="按内容搜索"
        v-model="keywords"
        @keydown.enter="serachnow"
      />
    </div>
    <!-- 导航栏 -->
    <div id="nav_wrap">
      <nav>
        <a href="#" class="cur">综合推荐 </a>
        <a href="#">销量</a>
        <a href="#">价格</a>
        <a href="#">好评度</a>
        <a href="#">店铺</a>
      </nav>
      <p><span class="iconfont">&#xe611;</span>分类</p>
    </div>
    <!-- 主体 -->
    <main>
      <h2>筛选11.11大促商品</h2>
      <div class="shopping" v-if="istrue">
        <div
          class="box"
          @click="goodsetail(item.id)"
          v-for="(item, index) in searchlist"
          :key="index"
        >
          <div class="left">
            <img :src="$pre + item.img" alt=""  />
          </div>
          <div class="right">
            <p>{{ item.goodsname }}</p>
            <p>
              <i>￥</i>
              <span>999</span>
              <del class="font">1099 </del>
              <b> 999人已付款</b>
            </p>
            <p>11.11限时299元起步</p>
            <p>999条评价 99.9%好评</p>
          </div>
        </div>
      </div>
      <div class="shopping" v-else>
        <div
          class="box"
          @click="goodsetail(item.id)"
          v-for="(item, index) in onegoodslist"
          :key="index"
        >
          <div class="left">
            <img :src="$pre + item.img" alt="" />
          </div>
          <div class="right">
            <p>{{ item.goodsname }}</p>
            <p>
              <i>￥</i>
              <span>999</span>
              <del class="font">1099 </del>
              <b> 999人已付款</b>
            </p>
            <p>11.11限时299元起步</p>
            <p>999条评价 99.9%好评</p>
          </div>
        </div>
      </div>
    </main>

    <footer></footer>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
export default {
  data() {
    return {
      keywords: "",
      istrue:false
    };
  },
  computed: {
    ...mapGetters({
      searchlist: "search/list",
      onegoodslist:"onegoods/list"
    }),
  },
  methods: {
    ...mapActions({
      reqChangeSearch: "search/reqChangeSearch",
      clearsearch : "search/clearsearch",
      reqChangeOnegoods:"onegoods/reqChangeOnegoods",
      clearonegoods:"onegoods/clearonegoods"
    }),
    serachnow() {
      if (this.keywords != "") {
        this.istrue=true
        this.reqChangeSearch(this.keywords);
      } 
    },
  },
  mounted() {
      this.reqChangeOnegoods({cateid:this.$route.query.num,type:Number(this.$route.query.type)});
  },
  beforeDestroy(){
    this.clearonegoods(),
    this.clearsearch()
  }
};
</script>

<style scoped>
/*头部*/
#top {
  height: 0.64rem;
  padding: 0.28rem 0.1rem 0.28rem 0.33rem;
  background-color: #ff6040;
  display: flex;
  color: #ffdfd8;
  justify-content: space-between;
  align-items: center;
}
#top .arrow_l {
  font-size: 0.34rem;
}
#top h2 {
  font-size: 0.32rem;
  margin: 0 1.23rem 0 2.55rem;
}
#top p {
  height: 0.64rem;
  width: 1.75rem;
  display: flex;
  border: 1px solid #ff8a6f;
  box-sizing: border-box;
  border-radius: 0.64rem;
  align-items: center;
  position: relative;
}
#top p span {
  width: 50%;
  height: 100%;
  text-align: center;
  line-height: 0.64rem;
}
#top p .line {
  width: 1px;
  height: 0.38rem;
  position: absolute;
  left: 0.87rem;
  top: 0.13rem;
  background-color: #fff;
}
#inp {
  width: 7.5rem;
  height: 0.83rem;
  background: linear-gradient(#ff6344, #ff877b);
  padding: 0 0.2rem 0.2rem 0.2rem;
  box-sizing: border-box;
   position: fixed;
  left: 0;
  top: 1.2rem;
}
#inp input {
  height: 0.63rem;
  width: 100%;
  border: 2px solid #e6e6e6;
  box-sizing: border-box;
  border-radius: 0.1rem;
  padding-left: 0.22rem;
  vertical-align: top;
}
#inp input::placeholder {
  color: #999999;
  font-size: 0.26rem;
}
#nav_wrap {
  height: 0.5rem;
  background: linear-gradient(to bottom, #ff7b69, #ff8a7f);
  display: flex;
  padding-top: 0.06rem;
  box-sizing: border-box;
  position: fixed;
  left: 0;
  top: 2rem;
}
#nav_wrap nav {
  display: flex;
  width: 6.2rem;
  height: 0.44rem;
  justify-content: space-between;
  padding: 0 0.4rem 0.2rem 0.18rem;
  box-sizing: border-box;
  background: url(../assets/images/line.jpg) no-repeat right top;
}
#nav_wrap nav a {
  color: #fff3f2;
  font-size: 0.26rem;
}
#nav_wrap nav a.cur {
  font-size: 0.3rem;
  margin-top: -0.05rem;
  font-weight: bold;
  position: relative;
}
#nav_wrap p {
  width: 1.4rem;
  color: #fff;
  text-align: center;
  font-size: 0.26rem;
  align-items: center;
}
#nav_wrap p span {
  vertical-align: middle;
  font-size: 0.26rem;
}
main {
  padding: 2.66rem 0.2rem 0;
  background-color: #fff;
  overflow: auto;
  /*商品信息*/
}
main h2 {
  width: 100%;
  height: 0.63rem;
  text-align: center;
  line-height: 0.63rem;
  border: 1px solid #ff6040;
  color: #ff6040;
  font-size: 0.38rem;
}
main .shopping .box {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  background-color: #fff;
}
main .shopping .box .left img {
  width: 2.16rem;
  height: 2.18rem;
}
main .shopping .box .right {
  width: 4.65rem;
  height: 2.18rem;
  font-size: 0.2rem;
}
main .shopping .box .right p:nth-child(1) {
  font-size: 0.3rem;
}
main .shopping .box .right p:nth-child(2) {
  margin-top: 0.15rem;
  font-size: 0.2rem;
  color: #9f9f9f;
}
main .shopping .box .right p:nth-child(2) i {
  color: #ff6040;
}
main .shopping .box .right p:nth-child(2) span {
  color: #ff6040;
  font-size: 0.3rem;
}
main .shopping .box .right p:nth-child(2) b {
  color: #999999;
  margin-left: 0.2rem;
}
main .shopping .box .right p:nth-child(3) {
  height: 0.33rem;
  width: 1.66rem;
  background-color: #ff8066;
  border: 1px solid #ffa997;
  box-sizing: border-box;
  color: #fff;
  text-align: center;
  line-height: 0.31rem;
  margin-top: 0.1rem;
}
main .shopping .box .right p:nth-child(4) {
  color: #999999;
  margin-top: 0.1rem;
}
/*尾部*/
footer {
  width: 2.68rem;
  height: 0.1rem;
  position: fixed;
  bottom: 0.18rem;
  left: 32.1%;
  background-color: #000;
  border-radius: 0.05rem;
}
</style>